package com.fmyexample.v2mcsecuritybootjdbc.sucerity;

import com.alibaba.fastjson.JSONObject;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.CreateCache;
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
import com.fmy.mcsecurity.config.McSecurityConfig;
import com.fmy.mcsecurity.config.builders.HttpMcSecurity;
import com.fmy.mcsecurity.integration.ClientSupportIntegration;
import com.fmy.mcsecurity.login.hander.LoginHandler;
import com.fmy.mcsecurity.starter.EnableMcSecurity;
import com.fmy.mcsecurity.token.TokenStorage;
import com.fmy.mcsecurity.token.impl.JdbcTokenStorage;
import com.fmy.mcsecurity.token.impl.JetcacheTokenStorage;
import com.fmy.mcsecurity.token.impl.jdbc.JdbcLoginService;
import com.fmy.mcsecurity.token.model.SecurityToken;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.protocol.RedisCommand;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.cors.CorsUtils;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Mr.fmy
 * @version 1.0.0
 * @ClassName SucerityJetCacheConfig
 * @Description TODO jetCache 模式
 * @createTime 2020/6/17 10:25
 */
@Configuration
@EnableCreateCacheAnnotation
public class SecurityJetCacheConfig extends SecurityAdapterConfig {

    //这里使用注解创建，当然也可以使用代码创建 可以参考https://github.com/alibaba/jetcache/wiki/Builder_CN
    @CreateCache(cacheType = CacheType.BOTH)
    private Cache jetCache;

    protected SecurityJetCacheConfig(UserDetailsService userDetailsService) {
        super(userDetailsService);
    }


    /**
     * 使用Jecache实现
     */
    public TokenStorage tokenStorage() {
        return new JetcacheTokenStorage(jetCache, 2);
    }
}
